package com.bluesky.jwf.component.dialog;

import com.bluesky.jwf.ComponentFactory;
import com.bluesky.jwf.component.Button;
import com.bluesky.jwf.component.Component;
import com.bluesky.jwf.component.Label;
import com.bluesky.jwf.component.event.AbstractEventHandler;
import com.bluesky.jwf.component.window.Dialog;
import com.bluesky.jwf.component.window.ModalResult;

public class MessageDialog extends Dialog {

	private Label messageLabel;

	private Button buttonOk;

	@Override
	public void init(String html) {

		super.init(html);

		setTitle("Message Dialog");

		messageLabel = (Label) ComponentFactory.getInstance().createComponent(
				"Label");
		bodyTag.loadByJwfClass("message").replace(messageLabel);

		buttonOk = (Button) ComponentFactory.getInstance().createComponent(
				"Button");
		buttonOk.setText("OK");
		bodyTag.loadByJwfClass("ok").replace(buttonOk);

		buttonOk.setClickHandler(new AbstractEventHandler() {
			@Override
			public void handle(Component target, Object parameter ) {

				modalResult = ModalResult.OK;

				close();

			}
		});

	}

	public String getMessage() {
		return messageLabel.getText();
	}

	public void setMessage(String message) {
		messageLabel.setText(message);
	}

}
